/*请求url*/
var urlData = require('../../../../../data/url.js');

Page({
  data: {
    //静态页面数据
    manageCheckArray: [],
    courseId:0,
    userId:0,
    userRole:0,
    showView: true,
    tishi:"没选择任何课程，故没有任何考勤",
    /*url*/
    teaListCourse: urlData.urlList.organManage.organCheck.teaListCourse.url,
    studentQuery: urlData.urlList.organManage.organCheck.studentQuery.url,
  },
  /*
   加载全部考勤
 */
  onLoad: function (e) {
    var that = this;
    wx.getStorage({
      key: 'loginConf',
      success: function (res) {
        that.setData({
          userId: res.data.userId,
          userRole : res.data.userRole
        });
        that.sendUserId(e);
      }
    })
  },
  /*
    发送用户id
  */
  sendUserId:function(e){
    var that = this;
    console.log(this.data.userRole)
    if(this.data.userRole==4){
      wx.request({
        url: this.data.teaListCourse,
        method: "get",
        data: {
          user_id:this.data.userId,
          role:this.data.userRole
        },
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        success: function (res) {
          if (res.data.code == 0) {
            // 刷新后来的列表数据
            // 判断后台返回的对象数组里面有没有东西，有则把提示去掉
             if(res.data.course_name!=null){
            that.listData(e, res);
            }
          }
        },
        fail: function (res) {
          console.log('刷list数据失败');
        }
      });
    }else if(this.data.userRole==5){
      wx.request({
        url: this.data.studentQuery, 
        method: "get",
        data: {
          user_id:this.data.userId,
          role:this.data.userRole
        },
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        success: function (res) {
          if (res.data.code == 0) {
            // 刷新后来的列表数据
            // 判断后台返回的对象数组里面有没有东西，有则把提示去掉
            if(res.data.course_name!=null){
            that.listData(e, res);
           }
          }
        },
        fail: function (res) {
          console.log('刷list数据失败');
        }
      });
    }
  },
  /*刷新数据*/
  listData: function (e, res) {
    this.setData({
      manageCheckArray: res.data.list,
       showView: false
    });
  },

  /*点击进入学生列表*/
  checkList: function (e) {
    var that = this;
    var role = this.data.userRole;
    var a = e.currentTarget;
    wx.setStorage({
      key: 'organCheckListCourseId',
      data: {
        course_Id: e.currentTarget.dataset.courseid
      }
    })
    if(role==4){
      wx.navigateTo({
        url: '../check-list/check-list'
      })
    }else if(role==5){
      return false;
    }
    
  }

})